<template>
  <div :class="prefixCls">
    <e-search
      v-model="currentQuery"
      is-enter
      size="middle"
      :placeholder="placeholder"
      @on-submit="handleClick"></e-search>
  </div>
</template>
<script>
export default {
  name: 'Search',
  props: {
    prefixCls: String,
    placeholder: String,
    query: String,
  },
  data () {
    return {
      currentQuery: this.query,
    }
  },
  watch: {
    query (val) {
      this.currentQuery = val;
    },
    currentQuery (val) {
      this.$emit('on-query-change', val);
    }
  },
  methods: {
    handleClick () {
      if (this.currentQuery === '') return;
      this.currentQuery = '';
      this.$emit('on-query-clear');
    }
  }
}
</script>
